package com.yxinsur.imc.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxinsur.imc.business.domain.ImcSupplierPersistencyDetail;
import com.yxinsur.imc.business.enums.IsDeletedEnum;
import com.yxinsur.imc.business.form.ImcSupplierPersistencyDetailForm;
import com.yxinsur.imc.business.mapper.ImcSupplierPersistencyDetailMapper;
import com.yxinsur.imc.business.service.IImcSupplierPersistencyDetailService;
import com.yxinsur.imc.business.vo.SupplierPersistencyDetailVo;
import com.yxinsur.imc.common.utils.DateUtils;
import com.yxinsur.imc.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商继续率子Service业务层处理
 *
 * @author imc
 * @date 2021-09-23
 */
@Service
public class ImcSupplierPersistencyDetailServiceImpl extends ServiceImpl<ImcSupplierPersistencyDetailMapper, ImcSupplierPersistencyDetail> implements IImcSupplierPersistencyDetailService {
    @Autowired
    private ImcSupplierPersistencyDetailMapper imcSupplierPersistencyDetailMapper;

    /**
     * 查询供应商继续率子
     *
     * @param id 供应商继续率子ID
     * @return 供应商继续率子
     */
    @Override
    public ImcSupplierPersistencyDetail selectImcSupplierPersistencyDetailById(String id) {
        return imcSupplierPersistencyDetailMapper.selectImcSupplierPersistencyDetailById(id);
    }

    /**
     * 查询供应商继续率子列表
     *
     * @param imcSupplierPersistencyDetail 供应商继续率子
     * @return 供应商继续率子
     */
    @Override
    public List<ImcSupplierPersistencyDetail> selectImcSupplierPersistencyDetailList(ImcSupplierPersistencyDetailForm imcSupplierPersistencyDetail) {
        ImcSupplierPersistencyDetail detail = new ImcSupplierPersistencyDetail();
        BeanUtils.copyProperties(imcSupplierPersistencyDetail,detail);
        detail.setIsDeleted(IsDeletedEnum.N.getCode());
        detail.setTenantId(SecurityUtils.getTenantId());
        return imcSupplierPersistencyDetailMapper.selectImcSupplierPersistencyDetailList(detail);
    }

    /**
     * 新增供应商继续率子
     *
     * @param imcSupplierPersistencyDetail 供应商继续率子
     * @return 结果
     */
    @Override
    public int insertImcSupplierPersistencyDetail(ImcSupplierPersistencyDetail imcSupplierPersistencyDetail) {
        imcSupplierPersistencyDetail.setCreateTime(DateUtils.getNowDate());
        return imcSupplierPersistencyDetailMapper.insertImcSupplierPersistencyDetail(imcSupplierPersistencyDetail);
    }

    /**
     * 修改供应商继续率子
     *
     * @param imcSupplierPersistencyDetail 供应商继续率子
     * @return 结果
     */
    @Override
    public int updateImcSupplierPersistencyDetail(ImcSupplierPersistencyDetailForm imcSupplierPersistencyDetail) {
        ImcSupplierPersistencyDetail detail = new ImcSupplierPersistencyDetail();
        BeanUtils.copyProperties(imcSupplierPersistencyDetail,detail);
        detail.setUpdateId(SecurityUtils.getUsername());
        detail.setUpdateTime(DateUtils.getNowDate());
        return imcSupplierPersistencyDetailMapper.updateImcSupplierPersistencyDetail(detail);
    }

    /**
     * 批量删除供应商继续率子
     *
     * @param ids 需要删除的供应商继续率子ID
     * @return 结果
     */
    @Override
    public int deleteImcSupplierPersistencyDetailByIds(String[] ids) {
        return imcSupplierPersistencyDetailMapper.deleteImcSupplierPersistencyDetailByIds(ids);
    }

    /**
     * 删除供应商继续率子信息
     *
     * @param id 供应商继续率子ID
     * @return 结果
     */
    @Override
    public int deleteImcSupplierPersistencyDetailById(String id) {
        return imcSupplierPersistencyDetailMapper.deleteImcSupplierPersistencyDetailById(id);
    }

    /**
     * 根据继续率主表查询继续率详情表的继续率信息
     * @param imcSupplierPersistencyDetail
     * @return
     */
    @Override
    public List<SupplierPersistencyDetailVo> selectDetailByPersistency(ImcSupplierPersistencyDetailForm imcSupplierPersistencyDetail) {
        Long supplierPersistencyId = imcSupplierPersistencyDetail.getSupplierPersistencyId();
        return imcSupplierPersistencyDetailMapper.selectSupplierPersistencyDetailVoList(supplierPersistencyId,SecurityUtils.getTenantId());
    }
}
